<?php
include_once(_CORE_PATH. "entity_prototype.php");
class UsersEntity extends entity_prototype
{
  
	public function SetUserId($id)
	{
		$this->Set('userid', (int)$id);		
	}
	
	public function GetAvatar()
	{
		$avatar = $this->Get('avatar');
		if (!strlen($avatar) && $this->Get('userid')) return MozgCfg::getProp('global/users//noAvatar');
		return $avatar;
	}

	public function GetGrantedGroups()
	{
		$groups = $this->Get('grantedGroups');
		if (!is_array($groups))
		{
			$this->SetGrantedGroupsNorm($groups);
			$groups = $this->Get('grantedGroups');
		}
		
		return $groups;
	}

	public function SetGrantedGroups(array $groups)
	{
		$groups = array_unique(array_map('intval', $groups));
		$this->Set('grantedGroups', $groups);
	}

	public function SetGrantedGroupsNorm($groupStr)
	{
		$groups = explode(',', trim((string)$groupStr, ','));
		$this->Set('grantedGroups', $groups);
	}	
	
	public function GetGrantedGroupsNorm()
	{
		$groups = $this->Get('grantedGroups');
		if (is_array($groups))
		{
			$groups = ',' .implode(',', $groups). ',';
		}
		
		return $groups;
	}	
}